package io.renren.modules.generator.service.impl;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.PrizeDao;
import io.renren.modules.generator.entity.PrizeEntity;
import io.renren.modules.generator.service.PrizeService;


@Service("prizeService")
public class PrizeServiceImpl extends ServiceImpl<PrizeDao, PrizeEntity> implements PrizeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PrizeEntity> wrapper = new QueryWrapper<>();
        if (MapUtils.isNotEmpty(params)) {
            /**
             * 查找参数
             */
            String key = MapUtils.getString(params, "key");

            if (StringUtils.isNotBlank(key)) {
                wrapper.like("prize_name", key);
            }
        }
        IPage<PrizeEntity> page = this.page(
                new Query<PrizeEntity>().getPage(params),
                new QueryWrapper<PrizeEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<PrizeEntity> queryAll() {
        return this.baseMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public List<PrizeEntity> queryByIndustryId(Integer industryId) {
        return this.baseMapper.selectList(new QueryWrapper<PrizeEntity>().eq("industry_id", industryId));
    }

}